﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RaytracerLib.Layers.OverlayCorrectors
{
    public class OverlapOverlayCorrector : OverlayCorrector
    {
        public OverlapOverlayCorrector(int a_width, int a_height, int a_margin)
            : base(a_width, a_height, a_margin)
        {
        }

        public override double CorrectUV(double a_uv)
        {
            return OverlapOverlayCorrector.Correct_UV(a_uv);
        }

        public static double Correct_UV(double a_uv)
        {
            a_uv %= 1;

            if (a_uv < 0)
                return 1 + a_uv;
            else
                return a_uv;
        }

        protected override int CorrectXY(int a_xy, int a_size)
        {
            return OverlapOverlayCorrector.Correct_XY(a_xy, a_size);
        }

        public static int Correct_XY(int a_xy, int a_size)
        {
            if (a_size == 0)
                return 0;

            a_xy %= a_size;

            if (a_xy < 0)
                return a_size + a_xy;
            else
                return a_xy;
        }
    }
}
